import cv2
import rospy
import time

time.sleep(10)

rospy.init_node("imageRecoder")

cap = cv2.VideoCapture("/dev/video17")
cap.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc(*"MJPG"))
cap.set(cv2.CAP_PROP_FPS, 30)


fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))
fps = cap.get(cv2.CAP_PROP_FPS)
width, height = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))

out = cv2.VideoWriter('/home/ninetripod/Videos/video_{}.mp4'.format(time.time()), fourcc, fps, (width, height))

print(fps, width, height, fourcc)

time0 = time.time()

while True:
    ref, frame = cap.read()
    if ref:
        out.write(frame)
        # cv2.imshow("video", frame)
    
    # c = cv2.waitKey(5) & 0xff
    # if c == 27:
    #     # 释放所有窗口
    #     cv2.destroyAllWindows()
    #     break

    # 录两分钟
    if time.time() - time0 > 60 * 1: 
        break

cap.release()
out.release()